home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 2
/
Deutsche Edition 2.iso
/
mac
/
POWERMAC
/
C64
/
SOURCE
/
Keyboard.c
< prev
next >
Wrap
Text File
|
1994-06-06
|
6KB
|
238 lines
/*
Commodore 64 Emulator v0.4 Earle F. Philhower III
Copyright (C) 1993-4 (st916w9r@dunx1.ocs.drexel.edu)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "Processor.h"
#include "Keyboard.h"
#include "Stack.h"
byte keyScan[8];
byte scanCode[256];
static void SetupScanCodes()
{
int x;
byte y, z;
for (x=0; x<256; x++)
{
z=255;
y=x^255;
if (y&1) z &=keyScan[0];
if (y&2) z &=keyScan[1];
if (y&4) z &=keyScan[2];
if (y&8) z &=keyScan[3];
if (y&16) z &=keyScan[4];
if (y&32) z &=keyScan[5];
if (y&64) z &=keyScan[6];
if (y&128) z &=keyScan[7];
scanCode[x]=z;
}
}
void AppleScanKeyboard(byte chr, int modifiers)
{
/* Clear out the scancodes */
keyScan[0]=keyScan[1]=keyScan[2]=keyScan[3]=keyScan[4]=keyScan[5]=keyScan[6]=keyScan[7]=255;
if (chr==13)
{
/* RETURN */
keyScan[0] -=2;
if (modifiers&shiftKey) keyScan[1]-=128;
SetupScanCodes();
return;
}
if (chr==0x08)
{
/* DELETE */
keyScan[0] -= 1;
if (modifiers&shiftKey) keyScan[1]-=128;
SetupScanCodes();
return;
}
if (chr==0x1b)
{
/* RUN/STOP */
keyScan[7]-=128;
SetupScanCodes();
return;
}
if (chr=='`')
{
/* RUN/STOP - RESTORE */
keyScan[7]-=128;
PushWord(pc);
Push(flags);
pc=WordAt(NMITo);
SetupScanCodes();
return;
}
if (modifiers&optionKey)
{
switch(chr)
{
/* F1, F2 */
case 0xaa: keyScan[1]-=128;
case 0xc1: keyScan[0]-=16; break;
/* F3, F4 */
case 0xa2: keyScan[1]-=128;
case 0xa3: keyScan[0]-=32; break;
/* F5, F6 */
case 0xa4: keyScan[1]-=128;
case 0xb0: keyScan[0]-=64; break;
/* F7, F8 */
case 0xa5: keyScan[1]-=128;
case 0xa6: keyScan[0]-=8; break;
}
SetupScanCodes();
return;
}
if (chr==' ')
{
/* SPACE */
if (modifiers&shiftKey) keyScan[1]-=128;
keyScan[7]-=16;
SetupScanCodes();
return;
}
if ((chr>=1)&&(chr<=26))
{
/* Make CONTROL down, munge the chars up into ASCII for following */
keyScan[7]-=4;
chr +=64+32;
}
if (((chr>='A')&&(chr<='Z'))||((chr>='a')&&(chr<='z')))
{
if (chr<'a') keyScan[1] -= 128;
else chr -=32;
switch (chr)
{
case 'A' : keyScan[1]-=4; break;
case 'B' : keyScan[3]-=16; break;
case 'C' : keyScan[2]-=16; break;
case 'D' : keyScan[2]-=4; break;
case 'E' : keyScan[1]-=64; break;
case 'F' : keyScan[2]-=32; break;
case 'G' : keyScan[3]-=4; break;
case 'H' : keyScan[3]-=32; break;
case 'I' : keyScan[4]-=2; break;
case 'J' : keyScan[4]-=4; break;
case 'K' : keyScan[4]-=32; break;
case 'L' : keyScan[5]-=4; break;
case 'M' : keyScan[4]-=16; break;
case 'N' : keyScan[4]-=128; break;
case 'O' : keyScan[4]-=64; break;
case 'P' : keyScan[5]-=2; break;
case 'Q' : keyScan[7]-=64; break;
case 'R' : keyScan[2]-=2; break;
case 'S' : keyScan[1]-=32; break;
case 'T' : keyScan[2]-=64; break;
case 'U' : keyScan[3]-=64; break;
case 'V' : keyScan[3]-=128; break;
case 'W' : keyScan[1]-=2; break;
case 'X' : keyScan[2]-=128; break;
case 'Y' : keyScan[3]-=2; break;
case 'Z' : keyScan[1]-=16; break;
}
SetupScanCodes();
return;
}
else if ((chr>='0')&&(chr<='9'))
{
switch(chr)
{
case '0': keyScan[4]-=8; break;
case '1': keyScan[7]-=1; break;
case '2': keyScan[7]-=8; break;
case '3': keyScan[1]-=1; break;
case '4': keyScan[1]-=8; break;
case '5': keyScan[2]-=1; break;
case '6': keyScan[2]-=8; break;
case '7': keyScan[3]-=1; break;
case '8': keyScan[3]-=8; break;
case '9': keyScan[4]-=1; break;
}
SetupScanCodes();
return;
}
else if ((chr>=0x1c)&&(chr<=0x1f))
{
switch (chr)
{
/* UP/DOWN */
case 0x1c: keyScan[1] -=128;
case 0x1d: keyScan[0] -=4; break;
/* LEFT/RIGHT */
case 0x1e: keyScan[1] -=128;
case 0x1f: keyScan[0] -=128; break;
}
SetupScanCodes();
return;
}
else if ((chr>='!')&&(chr<='/'))
{
switch (chr)
{
case '!': keyScan[1] -=128; keyScan[7] -=1; break;
case '"': keyScan[1] -=128; keyScan[7] -=8; break;
case '#': keyScan[1] -=128; keyScan[1] -=1; break;
case '$': keyScan[1] -=128; keyScan[1] -=8; break;
case '%': keyScan[1] -=128; keyScan[2] -=1; break;
case '&': keyScan[1] -=128; keyScan[2] -=8; break;
case 39 : keyScan[1] -=128; keyScan[3] -=1; break;
case '(': keyScan[1] -=128; keyScan[3] -=8; break;
case ')': keyScan[1] -=128; keyScan[4] -=1; break;
case '*': keyScan[6] -=2; break;
case '+': keyScan[5] -=1; break;
case ',': keyScan[5] -=128; break;
case '-': keyScan[5] -=8; break;
case '.': keyScan[5] -=16; break;
case '/': keyScan[6] -=128; break;
}
SetupScanCodes();
return;
}
else if ((chr>=':')&&(chr<='@'))
{
switch (chr)
{
case ';': keyScan[6]-=4;
case ':': keyScan[5]-=32; break;
case '<': keyScan[1]-=128; keyScan[5]-=128; break;
case '=': keyScan[6]-=32; break;
case '>': keyScan[1]-=128; keyScan[5]-=16; break;
case '?': keyScan[1]-=128; keyScan[6]-=128; break;
case '@': keyScan[5]-=64; break;
}
SetupScanCodes();
return;
}
}